package cc.eddic.pratice.programmingparadigms.emp03objlist.impl;

import cc.eddic.pratice.programmingparadigms.Result;
import cc.eddic.pratice.programmingparadigms.ResultComparator;
import cc.eddic.pratice.programmingparadigms.ResultPredicate;
import cc.eddic.pratice.programmingparadigms.emp02list.ResultList;
import cc.eddic.pratice.programmingparadigms.emp03objlist.ObjectComparator;
import cc.eddic.pratice.programmingparadigms.emp03objlist.ObjectList;
import cc.eddic.pratice.programmingparadigms.emp03objlist.ObjectPredicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ResultListZyzImpl extends ObjectList implements ResultList {

    private static final Logger log = LoggerFactory.getLogger(ResultListZyzImpl.class);

    public ResultListZyzImpl() {
        super();
    }

    public ResultListZyzImpl(int capacity) {
        super(capacity);
    }

    @Override
    public void add(Result result) {
        super.add(result);
    }

    @Override
    public Result get(int index) {
        return (Result) super.get(index);
    }

    @Override
    public Result findByGender(String gender) {
        return findByKey(gender);
    }

    @Override
    public Result findByDepartment(String department) {
        return findByKey(department);
    }

    @Override
    public Result findByJobTitle(String jobTitle) {
        return findByKey(jobTitle);
    }

    @Override
    public Result find(ResultPredicate predicate) {
        return (Result) super.find(new ObjectPredicate() {
            @Override
            public boolean test(Object obj) {
                return predicate.test((Result) obj);
            }
        });
    }

    @Override
    public void sort(ResultComparator comparator) {
        super.sort(new ObjectComparator() {
            @Override
            public int compare(Object o1, Object o2) {
                return comparator.compare((Result) o1, (Result) o2);
            }
        });
    }

    @Override
    public Result[] toArray() {
        Result[] arrResults = new Result[size()];
        for (int i = 0; i < size(); i++) {
            arrResults[i] = get(i);
        }
        return arrResults;
    }

}
